/// @tags: TreeChainPartition
#include <algorithm>
#include <cctype>
#include <cstdio>

namespace BlueQuantum {

int const N = 2e5 + 5, INF = 0x3f3f3f3f;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

struct Edge {
  int v, nxt, w;
} e[N << 1];

struct Node {
  int min, max, sum;
  bool tag;

  Node() : min(INF), max(-INF), sum(0), tag(false) {}

  inline void operator<<(Node const &rhs) {
    min = std::min(min, rhs.min);
    max = std::max(max, rhs.max);
    sum += rhs.sum;
  }

  inline void operator=(int x) { min = max = sum = x; }

} tr[N << 2];

int n, m, e_cnt, cnt;
int heads[N], fa[N], top[N], siz[N], dep[N], son[N], dfn[N], eid[N], data[N];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void dfs1(int u) {
  siz[u] = 1;
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa[u]) {
      dep[v] = dep[u] + 1, fa[v] = u, eid[(i + 1) >> 1] = v;
      dfs1(v);
      siz[u] += siz[v];
      if (siz[v] > siz[son[u]]) son[u] = v;
    }
  }
}

void dfs2(int u) {
  dfn[u] = ++cnt;
  if (son[u]) top[son[u]] = top[u], dfs2(son[u]);
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa[u]) {
      if (v != son[u]) {
        top[v] = v;
        dfs2(v);
      }
      data[dfn[v]] = e[i].w;
    }
  }
}

inline void pushup(int x) {
  tr[x].min = std::min(tr[x << 1].min, tr[x << 1 | 1].min);
  tr[x].max = std::max(tr[x << 1].max, tr[x << 1 | 1].max);
  tr[x].sum = tr[x << 1].sum + tr[x << 1 | 1].sum;
}

inline void pushdown(int x) {
  if (tr[x].tag) {
    Node &ls = tr[x << 1], &rs = tr[x << 1 | 1];
    std::swap(ls.min, ls.max);
    ls.max = -ls.max, ls.min = -ls.min;
    ls.sum = -ls.sum;
    std::swap(rs.min, rs.max);
    rs.max = -rs.max, rs.min = -rs.min;
    rs.sum = -rs.sum;
    ls.tag ^= true, rs.tag ^= true;
    tr[x].tag = false;
  }
}

void build(int x = 1, int l = 1, int r = n) {
  if (l == r) return tr[x] = data[l];
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}

void modify(int pos, int val, int x = 1, int l = 1, int r = n) {
  if (l == r) return tr[x] = val, void();
  int mid = (l + r) >> 1;
  pushdown(x);
  if (pos <= mid) modify(pos, val, x << 1, l, mid);
  else
    modify(pos, val, x << 1 | 1, mid + 1, r);
  pushup(x);
}

void neg(int L, int R, int x = 1, int l = 1, int r = n) {
  if (L <= l && r <= R)
    return tr[x].tag ^= true, tr[x].max = -tr[x].max, tr[x].min = -tr[x].min,
                              tr[x].sum = -tr[x].sum, std::swap(tr[x].min, tr[x].max);
  int mid = (l + r) >> 1;
  pushdown(x);
  if (L <= mid) neg(L, R, x << 1, l, mid);
  if (mid < R) neg(L, R, x << 1 | 1, mid + 1, r);
  pushup(x);
}

void negPath(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) std::swap(u, v);
    neg(dfn[top[u]], dfn[u]);
    u = fa[top[u]];
  }
  if (dep[u] < dep[v]) std::swap(u, v);
  if (u != v) neg(dfn[v] + 1, dfn[u]);
}

inline Node query(int L, int R, int x = 1, int l = 1, int r = n) {
  if (L <= l && r <= R) return tr[x];
  int mid = (l + r) >> 1;
  pushdown(x);
  Node res;
  if (L <= mid) res << query(L, R, x << 1, l, mid);
  if (mid < R) res << query(L, R, x << 1 | 1, mid + 1, r);
  return res;
}

inline Node queryPath(int u, int v) {
  Node res;
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) std::swap(u, v);
    res << query(dfn[top[u]], dfn[u]);
    u = fa[top[u]];
  }
  if (dep[u] < dep[v]) std::swap(u, v);
  if (u != v) res << query(dfn[v] + 1, dfn[u]);
  return res;
}

inline int main() {
  read(n);
  for (int i = 1, u, v, w; i < n; ++i) {
    ++read(u), ++read(v), read(w);
    add(u, v, w), add(v, u, w);
  }
  fa[1] = top[1] = 1, dfs1(1), dfs2(1), build();
  char opt[4];
  read(m);
  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%s", opt);
    ++read(u), ++read(v);
    switch (opt[0] + opt[1]) {
      case 'C':
        modify(dfn[eid[u - 1]], v - 1);
        break;
      case 'N':
        negPath(u, v);
        break;
      case 'S' + 'U':
        printf("%d\n", queryPath(u, v).sum);
        break;
      case 'M' + 'A':
        printf("%d\n", queryPath(u, v).max);
        break;
      case 'M' + 'I':
        printf("%d\n", queryPath(u, v).min);
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P1505 [国家集训队]旅游.in", "r", stdin);
  freopen("P1505 [国家集训队]旅游.out", "w", stdout);
#endif
#endif

  return BlueQuantum::main();
}